<?php
include_once('common/header.php');
$strRefer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
if($AppUI->id <= 0 || $strRefer == '') {
	$arrJson 	= array('error'=>1,'msg'=>$arrError[1]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	exit();
}

$intAction 	= $objRequest->getParam('act',null);
$intPlaceId 	= $objRequest->getParam('placeid',null);
$intPage	= $objRequest->getParam('page', 1);
$intError	= 0;
$objPlace 	= new Place();
$strMessage	= '';
$intLike	= 0;
if(isset($intAction)) {
	if($intAction == 1) {
		$intError = $objPlace->addLike($AppUI->id, $intPlaceId);		
		if($intError > 0) $intError = 28;
		else $strMessage = $arrMessage[9];
	}
	elseif($intAction == 2) {
		$intError = $objPlace->deleteFavourite($AppUI->id, $intPlaceId);
		if($intError > 0) $intError = 30;
		else $strMessage = $arrMessage[8];
	}
}	
if($intError == 0) {
	if($intAction == 1) {
		$intTotal = 0;
		$fav = $objPlace->getLikeList($intPlaceId, 0, 28, $intTotal);
		$this->view->num = count($fav);
		$this->view->fav = $fav;
		$this->view->totalfav = $intTotal;
		$this->view->intPlaceId = $intPlaceId;
		
		$objView	= Zend_Registry::get('objView');			
		$strData	= $objView->fetch('place/box-user-like.tpl');
		$arrJson	= array('error'=>0,'msg'=>$strMessage,'data'=>$strData);
	} elseif($intAction == 2) {
		$intTotal = 0;
		$intLimit = COMMENT_LIMIT;
		$intOff = ($intPage -1)*$intLimit;
		$strUrl	= HOST_VFRIEND . 'place/favorite?';
		$fav = $objPlace->getFavourList($AppUI->id, $intOff, $intLimit, $intTotal);
		$this->view->arrPlaces	 	= $fav;

		$this->view->intPage		= $intPage;
		$this->view->intTotal		= $intTotal;
		$this->view->intOffset		= $intOff;
		$this->view->intLimit		= $intLimit;
		$this->view->strUrl			= $strUrl;
		
		$objView	= Zend_Registry::get('objView');			
		$strData	= $objView->fetch('place/box-favourite.tpl');
		$arrJson	= array('error'=>0,'msg'=>$strMessage,'data'=>$strData);
	}elseif($intAction > 1) {		
		$arrJson	= array('error'=>0,'msg'=>$strMessage);
	}
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	
} else {
	$arrJson 	= array('error'=>1,'msg'=>$arrError[$intError]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
}
exit();
?>
